#include "clickable_label.h"

// constructor and destructor
ClickableLabel::ClickableLabel(Widget* _parent, Engine* _engine, QString _text,
      int _x, int _y, int _w, int _h, TextAlignment _textAlignment)
          :Label(_parent, _engine, _text, _x, _y, _w, _h, _textAlignment)
{
    underlined = true;
    penBlue = 255;
    mouseTracking = true;
}

ClickableLabel::~ClickableLabel(){}

// paint
void ClickableLabel::Paint(QPainter &widget_painter)
{
    Label::Paint(widget_painter);
}

// mouse handling
void ClickableLabel::OnMouseMoved(QMouseEvent *e, bool onWidget, int x_rel, int y_rel)
{
    if(onWidget)
    {
        penGreen = 200;
        penBlue = 0;
    }else
    {
        penGreen = 0;
        penBlue = 255;
    }
}

void ClickableLabel::OnMousePressed(QMouseEvent *e, bool inside, int x_rel, int y_rel)
{
    if(inside)
    {
        penGreen = 100;
    }
}

void ClickableLabel::OnMouseReleased(QMouseEvent *e, bool inside, int x_rel, int y_rel)
{
    if(inside)
    {
        penGreen = 200;
    }else
    {
        penGreen = 0;
    }
}

void ClickableLabel::OnMouseClick(QMouseEvent *e, int x_rel, int y_rel)
{
    for(int i=0; i<listeners.size(); i++)
    {
        listeners.at(i)->OnClick(this);
    }
}

// listeners handling
void ClickableLabel::AddClickableListener(ClickableLabelListener* cl)
{
    listeners.append(cl);
}
